package org.fujene.sandbox;

import java.io.IOException;

import org.fujene.communicate.repli.ReplicatePeerSystem;
import org.fujene.structure.Queue;
import org.fujene.structure.ExtendResult;
import org.fujene.structure.SearchQueue;

import junit.framework.TestCase;

public class TestDemo extends TestCase{
	private static void showResult(ExtendResult result){
		System.out.println("Total: " + result.getTotal());
		System.out.println("Time:  " + result.getTime() + " sec.");

		for(int i = 0; i < result.getLength(); i++){
			System.out.printf("%2d: ID=%4d, %s%n", i, result.getQueue(i).ID, result.getQueue(i).contents[0]);
		}
	}

	public static void testAll() throws InterruptedException, IOException{
		ReplicatePeerSystem mainSystem = new ReplicatePeerSystem();
		mainSystem.testMain(null);

		// index
		mainSystem.setNewIndex(new Queue(new String[]{ "Apple" }, new String[]{}, 1000));
		mainSystem.setNewIndex(new Queue(new String[]{ "Orange" }, new String[]{}, 1001));
		mainSystem.setNewIndex(new Queue(new String[]{ "Grape" }, new String[]{}, 1002));
		mainSystem.setNewIndex(new Queue(new String[]{ "Milk" }, new String[]{}, 1003));
		mainSystem.setNewIndex(new Queue(new String[]{ "林檎" }, new String[]{}, 1004));
		mainSystem.setNewIndex(new Queue(new String[]{ "蜜柑" }, new String[]{}, 1005));
		mainSystem.setNewIndex(new Queue(new String[]{ "葡萄" }, new String[]{}, 1006));
		mainSystem.setNewIndex(new Queue(new String[]{ "桜桃" }, new String[]{}, 1007));
		mainSystem.setNewIndex(new Queue(new String[]{ "Fact is stranger than fiction." }, new String[]{},
				1008));
		mainSystem.setNewIndex(new Queue(new String[]{ "It's no use crying over spilled milk." },
				new String[]{}, 1009));
		mainSystem.setNewIndex(new Queue(new String[]{ "桃栗三年柿八年" }, new String[]{}, 1010));
		mainSystem.setNewIndex(new Queue(new String[]{ "李も桃も桃のうち" }, new String[]{}, 1011));
		mainSystem.setNewIndex(new Queue(new String[]{ "相撲も桃も桃のうち" }, new String[]{}, 1012));

		// search
		try{
			showResult(mainSystem.setNewSearch(new SearchQueue("milk", "content", 0, 10)));
			showResult(mainSystem.setNewSearch(new SearchQueue("林檎", "content", 0, 10)));
			showResult(mainSystem.setNewSearch(new SearchQueue("桃", "content", 0, 10)));
		}catch(Exception e){}
	}
}
